package com.lechuang.taoshangyou.view.activity.recyclerView;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.MemoryCategory;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lechuang.taoshangyou.R;
import com.lechuang.taoshangyou.model.bean.GetBean;
import com.lechuang.taoshangyou.view.activity.get.OnKeyShareCallback;
import com.lechuang.taoshangyou.view.defineView.SpannelTextView;

import java.util.Locale;

/**
 * Author: guoning
 * Date: 2017/10/6
 * Description:  赚列表页面的Adapter
 */

public class GetInfoAdapter extends BaseQuickAdapter<GetBean.ListInfo,GetInfoHolder> {


    private OnKeyShareCallback callback;
    private Context context;
    public GetInfoAdapter(Context context) {
        super(R.layout.item_get);
        this.context = context;
    }

    @Override
    protected void convert(final GetInfoHolder helper, final GetBean.ListInfo listInfo) {
        SpannelTextView spannelTextView = helper.getView(R.id.spannelTextView);
        spannelTextView.setShopType(listInfo.shopType);
        spannelTextView.setDrawText(listInfo.name);
        Glide.with(context).load(listInfo.img).into((ImageView) helper.getView(R.id.img));
        Glide.get(context).setMemoryCategory(MemoryCategory.LOW);

        helper.setText(R.id.price,String.format("%s", listInfo.price));
        ((TextView)helper.getView(R.id.price)).getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);
        helper.setText(R.id.preferentialPrice,"¥"+listInfo.preferentialPrice);
        helper.setText(R.id.nowNumber,"已售"+ listInfo.nowNumber +"件");
        helper.setText(R.id.couponMoney,String.format(Locale.CHINESE,"%d元", listInfo.couponMoney));
        helper.setText(R.id.zhuanMoney,listInfo.zhuanMoney);
       SpannelTextView productName =  helper.getView(R.id.spannelTextView);
        productName.setShopType(listInfo.shopType);
        productName.setDrawText(listInfo.productName);
        final View ll_get_good = helper.getView(R.id.ll_get_good);
        final View share = helper.getView(R.id.share);

        final int adapterPosition = helper.getAdapterPosition();
        share.setTag(adapterPosition);
        ll_get_good.setTag(adapterPosition);
//        final CommFragment.InfoHolder tempHolder = holder;
       /* share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = (Integer) share.getTag();
                if (pos!=adapterPosition)return;
                if (callback!=null)callback.show(listInfo,adapterPosition,share.getId());
            }
        });*/
        ll_get_good.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int pos = (Integer) share.getTag();
                if (pos!=adapterPosition)return;
                if (callback!=null)callback.show(listInfo,adapterPosition,ll_get_good.getId());
            }
        });

    }


    public void setOnKeyShareCallback(OnKeyShareCallback callback) {
        this.callback = callback;
    }

}
